package com.cz.background.controller.common;

import com.cz.background.common.dto.PageResponseResult;
import com.cz.background.dto.common.role.AddRoleDTO;
import com.cz.background.dto.common.role.RoleQueryDTO;
import com.cz.background.dto.common.role.UpdateRoleDTO;
import com.cz.background.dto.common.role.UpdateRoleStatusDTO;
import com.cz.background.entity.common.SysRole;
import com.cz.background.service.common.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
@Tag(name = "角色管理")
public class RoleController {

    @Autowired
    private SysRoleService roleService;

    @PostMapping("page")
    @Operation(summary = "分页查询 角色列表")
    public PageResponseResult<SysRole> page(@RequestBody RoleQueryDTO roleQueryDTO) {
        return roleService.queryRolePage(roleQueryDTO);
    }

    @PostMapping("list")
    @Operation(summary = "查询 角色列表")
    public List<SysRole> list() {
        return roleService.queryRoleList();
    }

    @PostMapping("addRole")
    @Operation(summary = "新增角色")
    public void addRole(@RequestBody @Valid AddRoleDTO addRoleDTO) {
        roleService.addRole(addRoleDTO);
    }

    @PostMapping("delRole")
    @Operation(summary = "删除角色")
    public void deleteRole(@RequestBody List<String> ids) {
        roleService.delRole(ids);
    }

    @PostMapping("updateRole")
    @Operation(summary = "更新角色")
    public void updateRole(@RequestBody @Valid UpdateRoleDTO updateRoleDTO) {
        roleService.updateRole(updateRoleDTO);
    }

    @PostMapping("updateRoleStatus")
    @Operation(summary = "更新角色状态")
    public void updateRoleStatus(@RequestBody @Valid UpdateRoleStatusDTO updateRoleStatusDTO) {
        roleService.updateRoleStatus(updateRoleStatusDTO);
    }
}